package org.xdq.demo.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.xdq.demo.dto.GoodsDto;
import org.xdq.demo.dto.PageParam;
import org.xdq.demo.mapper.GoodsMapper;
import org.xdq.demo.model.Goods;
import org.xdq.demo.service.GoodsService;
import org.xdq.demo.util.DemoUtils;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

@Service
@Transactional
public class GoodsServiceImpl implements GoodsService {

	@Autowired
	private GoodsMapper goodsMapper;
	
	@Override
	public Map<String,Object> getGoodsList(PageParam pageParam) {
		PageHelper.startPage(pageParam);
		List<Goods> list = goodsMapper.findGoodsList(pageParam);
		PageInfo<Goods> page = new PageInfo<Goods>(list);
		
		return DemoUtils.convert2PageData(page);
		
		
	}

	@Override
	public int addNewGoods(GoodsDto dto) {
		
		return goodsMapper.saveNewGoods(dto);
	}

	@Override
	public void deleteGoods(Integer... gids) {
		goodsMapper.deleteGoods(gids);
		
	}

	@Override
	public void editGoods(GoodsDto dto) {
		goodsMapper.updateGoods(dto);
	}

}
